package com.ayuer.chapter06;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.concurrent.ConcurrentHashMap;

public class TreeTraversal {
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        public TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public static void preOrder(TreeNode root) {
        if (root == null) {
            return;
        }
        //先根
        System.out.print(root.val + "->");
        preOrder(root.left);
        preOrder(root.right);
    }

    public static void inOrder(TreeNode root) {
        if (root == null) {
            return;
        }

        inOrder(root.left);
        System.out.print(root.val + "->");
        inOrder(root.right);
    }

    public static void postOrder(TreeNode root) {
        if (root == null) {
            return;
        }
        postOrder(root.left);
        postOrder(root.right);
        System.out.print(root.val + "->");

    }


    public static void main(String[] args) {
//        LinkedList
//        ArrayList
//        PriorityQueue
//        HashMap
//        ConcurrentHashMap
//        StringBuilder
//        StringBuffer
//        Object
        TreeNode t1 = new TreeNode(1, null, null);
        TreeNode t2 = new TreeNode(2, null, null);
        TreeNode t3 = new TreeNode(3, null, null);
        TreeNode t4 = new TreeNode(4, t2, t1);
        TreeNode t5 = new TreeNode(5, t4, t3);
        TreeNode t6 = new TreeNode(7, null, null);
        TreeNode root = new TreeNode(6, t6, t5);
        TreeTraversal.preOrder(root);
        System.out.println();
        TreeTraversal.inOrder(root);
        System.out.println();
        TreeTraversal.postOrder(root);
    }


}
